﻿
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<h2>试题</h2>
<input type="button" value="全选！" onclick="CountCheck()" />
<input type="button" value="取消选中！" onclick="callChecked()" />
<input type="button" value="选中所有奇数！" onclick="oddChecked()" />
<input type="button" value="反选！" onclick="InvertChecked()" />

<div id="ItemList">
</div>



<div><input type="submit" value="删除选中！"  onclick="IsDeleteItem()"/></div>
<script>
    $(function () {
        Examlist();
    })
    function Examlist() {
     
        $.ajax({
            url:"/TrainRoced/ItembankList1",
            type: "get",
            success:function (obj) {
                obj = eval(obj)
             
                $("#ItemList").empty();

                for (var i = 0; i < obj.length; i++) {
                    $("#ItemList").append("<h3><input type='checkbox' name='ItemBank' value='" + obj[i].ItemId + "' /><span style='font-size:24PX;'>" + obj[i].ItemId + "." + obj[i].ItemName + "</span></h3>")
                }
              
            }
        })
    }
    function IsDeleteItem() {
        var ItemId = "";
        var CountH3 = $("#ItemList h3").length;
   
        var obj = document.getElementsByName('ItemBank');
        for (var i = 0; i < CountH3 ; i++) {
        
            if (obj[i].checked) ItemId += obj[i].value + ',';  //如果选中，将value添加到变量s中    
          
          
            
           
        }
        ItemId = ItemId.substring(0, ItemId.length - 1);
      
        $.ajax({
            url: "/TrainRoced/DeleteItem",
            type: "get",
            data: {  id:ItemId },
            success: function (obj) {
                if (obj > 0) {


                    alert("删除成功 ");
                    location.href="/";

                }
                else {
                    alert('系统繁忙！');
                }
            }

        })



    }







  function  CountCheck (){  
   
      $("[name='ItemBank']").attr("checked", 'true');//全选  
            } 
  function callChecked (){  
      $("[name='ItemBank']").removeAttr("checked");//取消全选  
            }  
  function  oddChecked(){  
      $("[name='ItemBank']:even").attr("checked", 'true');//选中所有奇数  
            } 
  function InvertChecked(){  
      $("[name='ItemBank']").each(function () {//反选  
                if($(this).attr("checked")){  
                    $(this).removeAttr("checked");  
                   }  
                else{  
                   $(this).attr("checked",'true');  
                    }  
                })  
           }  
     
</script>
